"""扫描记录扩展数据模型"""
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, JSON, func, UniqueConstraint
from app.database import Base


class ScanRecordExtension(Base):
    """扫描记录扩展数据表"""
    __tablename__ = "scan_record_extensions"

    id = Column(Integer, primary_key=True, index=True)
    record_id = Column(Integer, ForeignKey("scan_records.id", ondelete="CASCADE"), nullable=False, comment="扫描记录ID")
    field_name = Column(String(100), nullable=False, comment="字段名称(关联field_configs)")
    field_value = Column(JSON, nullable=False, comment="字段值")
    created_at = Column(DateTime, server_default=func.now(), comment="创建时间")

    # 唯一约束
    __table_args__ = (UniqueConstraint("record_id", "field_name", name="uq_record_field"),)

